home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / demo / GDS_MISC.lha / misc / random.c < prev    next >
C/C++ Source or Header  |  1994-04-15  |  7KB  |  263 lines

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <exec/types.h>
  5. #include <graphics/gfx.h>
  6. #include <graphics/gfxbase.h>
  7.  
  8. #include <proto/exec.h>
  9. #include <proto/graphics.h>
  10.  
  11. #include "GameSmith:GameSmith.h"
  12. #include "GameSmith:include/proto/all_regargs.h"
  13. #include "GameSmith:include/libraries/libptrs.h"
  14.  
  15. /*-------------------------------------------------------------------------*/
  16.  
  17. #define VIDEO_STEPS        30
  18. #define COLOR_GRADIENT    0x100                /* color change amount */
  19. #define VIDEO_REG            0x180                /* address of bg color reg */
  20. #define BGCOLOR            0xf00                /* max color value (bright red) */
  21. #define BGCOLOR_LONG        0x00ff0000        /* 8 bit color entry (bright red) */
  22. #define FGCOLOR_LONG        0x00ffff00        /* bright yellow */
  23.  
  24. /*-------------------------------------------------------------------------*/
  25. /* Function Prototypes                                                                       */
  26.  
  27. void parser(int,char **);
  28. int setup(void);
  29. void build_copper(void);
  30. void plot_points(void);
  31. int check_close(void);
  32. void cleanup(void);
  33.  
  34. /*-------------------------------------------------------------------------*/
  35. /* some global variables                                                   */
  36.  
  37. int swidth,sheight,smode;
  38.  
  39. /*-------------------------------------------------------------------------*/
  40.  
  41. unsigned short copper_list[256];    /* enough for our custom copper list */
  42.  
  43. struct copper_struct copper = 
  44.     {
  45.     copper_list,
  46.     NULL,
  47.     NULL
  48.     };
  49.  
  50. unsigned long ctbl[2] = {BGCOLOR_LONG,FGCOLOR_LONG};
  51.  
  52. struct gs_viewport vp =
  53.     {
  54.     NULL,                                    /* ptr to next viewport */
  55.     ctbl,                                    /* ptr to color table */
  56.     2,                                        /* number of colors in table */
  57.     &copper,                                /* ptr to user copper list */
  58.     0,0,0,0,0,                            /* height, width, depth, bmheight, bmwidth */
  59.     0,0,                                    /* top & left viewport offsets */
  60.     0,0,                                    /* X & Y bitmap offsets */
  61.     GSVP_ALLOCBM,                        /* flags (alloc bitmap) */
  62.     NULL,NULL,                            /* 2.xx & above compatibility stuff */
  63.     NULL,NULL,                            /* bitmap pointers */
  64.     NULL,                                    /* future expansion */
  65.     0,0,0,0                                /* display clip (use nominal) */
  66.     };
  67.  
  68. struct display_struct display =
  69.     {
  70.     NULL,                                    /* ptr to previous display view */
  71.     NULL,NULL,                            /* 2.xx & above compatibility stuff */
  72.     0,0,                                    /* X and Y display offsets */
  73.     0,                                        /* display mode ID */
  74.     0,                                        /* flags */
  75.     &vp,                                    /* ptr to 1st viewport */
  76.     NULL                                    /* future expansion */
  77.     };
  78.  
  79. /***************************************************************************/
  80.  
  81. main(argc,argv)
  82. int argc;
  83. char *argv[];
  84.  
  85. {
  86.     int err,end=0;
  87.  
  88.     if (gs_open_libs(GRAPHICS,0))    /* open AmigaDOS libs */
  89.         exit(01);                    /* if can't open libs, abort */
  90.     parser(argc,argv);            /* parse command line args */
  91.     if (err=setup())                /* if couldn't get set up... abort program */
  92.         {
  93.         printf("\nSetup error: %d\n",err);
  94.         gs_close_libs();            /* close all libraries */
  95.         exit(02);
  96.         }
  97.     while (!end)                    /* this shows off speed */
  98.         {
  99.         plot_points();
  100.         gs_show_display(&display,1);    /* make sure mouse blanker doesn't mess us up */
  101.         end=check_close();        /* end when user hits left mouse button */
  102.         }
  103.     cleanup();                        /* close & deallocate everything */
  104.     gs_close_libs();                /* close all libraries */
  105. }
  106.  
  107. /***************************************************************************/
  108.  
  109. void parser(argc,argv)
  110. int argc;
  111. char *argv[];
  112.  
  113. {
  114.     swidth=320;                        /* default width & height */
  115.     sheight=200;
  116.     smode=0;                            /* default mode of lores no lace */
  117.     if ((argc >= 2) && (!(strcmp(argv[1],"?"))))
  118.         {
  119.         printf("\nUSAGE: vector [HIRES] [SUPER]\n");
  120.         return;
  121.         }
  122.     else if (argc >= 2)
  123.         {
  124.         if (!(stricmp(argv[1],"HIRES")))    /* check for hires spec */
  125.             {
  126.             swidth=640;
  127.             sheight=400;
  128.             smode|=HIRES|LACE;
  129.             }
  130.         else if (!(stricmp(argv[1],"SUPER")))    /* check for superhires */
  131.             {
  132.             #ifdef SUPER72_MONITOR_ID
  133.             if (GfxBase->LibNode.lib_Version >= 36)
  134.                 {
  135.                 if (ModeNotAvailable(SUPER72_MONITOR_ID | SUPERLACE_KEY))
  136.                     {
  137.                     swidth=640;
  138.                     sheight=400;
  139.                     smode=HIRES|LACE;
  140.                     }
  141.                 else
  142.                     {
  143.                     smode=SUPER72_MONITOR_ID | SUPERLACE_KEY;
  144.                     swidth=800;
  145.                     sheight=600;
  146.                     }
  147.                 }
  148.             else
  149.             #endif
  150.                 {
  151.                 swidth=640;
  152.                 sheight=400;
  153.                 smode=HIRES|LACE;
  154.                 }
  155.             }
  156.         }
  157. }
  158.  
  159. /***************************************************************************/
  160.  
  161. int setup()
  162.  
  163. {
  164.     vp.height = sheight;                    /* set up display dimensions */
  165.     vp.width = swidth;
  166.     vp.depth = 1;
  167.     vp.bmheight = sheight;
  168.     vp.bmwidth = swidth;
  169.     display.modes = smode;
  170.     build_copper();                        /* build custom copper list */
  171.     if (gs_create_display(&display))
  172.         {
  173.         return(-1);
  174.         }
  175.     gs_show_display(&display,1);
  176.     return(0);
  177. }
  178.  
  179. /***************************************************************************/
  180.  
  181. void build_copper()
  182.  
  183. /* build a custom copper list of background color changes */
  184.  
  185. {
  186.     int cnt,cnt2=0,video_gradient;
  187.     short bgcolor,gradient;
  188.  
  189.     bgcolor=BGCOLOR;
  190.     gradient=0;
  191.     video_gradient=(sheight/3)/15;
  192.     copper_list[cnt2++]=UC_NOSPRITES;        /* turn off sprites */
  193.     for (cnt=0; cnt < 16; cnt++)                /* build copper list */
  194.         {
  195.         if (cnt)
  196.             {
  197.             copper_list[cnt2++]=UC_WAIT;        /* copper wait instruction */
  198.             copper_list[cnt2++]=gradient;        /* y coord to wait on */
  199.             copper_list[cnt2++]=0;                /* x coord to wait on */
  200.             }
  201.         copper_list[cnt2++]=UC_MOVE;            /* copper move instruct */
  202.         copper_list[cnt2++]=VIDEO_REG;        /* register to affect */
  203.         copper_list[cnt2++]=bgcolor;            /* value for register */
  204.         gradient+=video_gradient;
  205.         bgcolor-=COLOR_GRADIENT;
  206.         if (bgcolor < 0)
  207.             bgcolor=0;
  208.         }
  209.     gradient=(sheight/3)*2;                        /* build bottom color gradient */
  210.     bgcolor+=COLOR_GRADIENT;
  211.     for (cnt=0; cnt < 15; cnt++)                /* build copper list */
  212.         {
  213.         copper_list[cnt2++]=UC_WAIT;            /* copper wait instruction */
  214.         copper_list[cnt2++]=gradient;            /* y coord to wait on */
  215.         copper_list[cnt2++]=0;                    /* x coord to wait on */
  216.         copper_list[cnt2++]=UC_MOVE;            /* copper move instruct */
  217.         copper_list[cnt2++]=VIDEO_REG;        /* register to affect */
  218.         copper_list[cnt2++]=bgcolor;            /* value for register */
  219.         gradient+=video_gradient;
  220.         bgcolor+=COLOR_GRADIENT;
  221.         if (gradient > sheight)
  222.             gradient=sheight;
  223.         if (bgcolor > BGCOLOR)
  224.             bgcolor=BGCOLOR;
  225.         }
  226.     copper_list[cnt2++]=UC_END;                /* end coppper list */
  227. }
  228.  
  229. /***************************************************************************/
  230.  
  231. void plot_points()
  232.  
  233. /* plot random points on the screen */
  234.  
  235. {
  236.     int cnt;
  237.  
  238.     for (cnt=0; cnt < 1000; cnt++)
  239.         gs_plot(vp.bitmap1,_gs_random(swidth),_gs_random(sheight),1);
  240. }
  241.  
  242. /***************************************************************************/
  243.  
  244. int check_close()
  245.  
  246. /* check for user input */
  247.  
  248. {
  249.     if (gs_joystick(0) & JOY_BUTTON1)
  250.         return(1);
  251.     return(0);
  252. }
  253.  
  254. /***************************************************************************/
  255.  
  256. void cleanup()
  257.  
  258. /* release all resources and memory */
  259.  
  260. {
  261.     gs_remove_display(&display);
  262. }
  263.